/**
 * 
 */
package edu.pw.treegrid.server.reportmodel;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import edu.pw.treegrid.server.query.Node;
import edu.pw.treegrid.server.classmodel.SimpleAttribute;
import edu.pw.treegrid.server.query.TableNode;
import edu.pw.treegrid.server.service.XMLMarshaller;
import xalan.xml.XMLUtils;

/** 
 * @author Xalan
 */
public class ReportReferenceColumn extends ReportColumn {

	public ReportReferenceColumn(String name) {
		super(name);
	}
	
	private ReportColumn referenceColumn;

	public ReportColumn getReferenceColumn() {
		return referenceColumn;
	}

	public void setReferenceColumn(ReportColumn referenceColumn) {
		this.referenceColumn = referenceColumn;
	}

	/** 
	 * /* (non-Javadoc)
	 *  * @see ReportColumn#buildQueryNode()
	 */
	public Node buildQueryNode() {
		TableNode tn = (TableNode) getDomainAttribute().buildQueryNode(this);
		//tn.setReportColumn(this);
		tn.addChild(getReferenceColumn().buildQueryNode());
		return tn;
	}

	/** 
	 * /* (non-Javadoc)
	 *  * @see ReportColumn#getSimpleAttribute()
	 */
	public SimpleAttribute getSimpleAttribute() {
		return getReferenceColumn().getSimpleAttribute();
	}

	@Override
	protected void serializeToXML(Document document, Element columnElement) {
		columnElement.appendChild(referenceColumn.serializeToXML(document));
	}

	@Override
	protected boolean isSerialize() {
		return true;
	}
	
	@Override
	protected void deserializeFromXML(Element e, XMLMarshaller marshaller) {
		super.deserializeFromXML(e, marshaller);
		this.referenceColumn = ReportColumn.newColumn(
				XMLUtils.getFirstElement(e, COLUMN_ELEMENT), marshaller
		);
	}

	@Override
	public String getImageSrc() {
		return getReferenceColumn().getImageSrc();
	}

	@Override
	public ReportSimpleColumn getReportSimpleColumn() {
		return getReferenceColumn().getReportSimpleColumn();
	}	
	
}